﻿using Common.Commands;
using Common.Commands.MemberCommands;
using Core.Domain.Model;
using Dto.ApiResponses.MemberResponses;
using Sanelib.DataOperation;

namespace Core.Processors.MemberProcessors
{
    public class RegisterMemberCardProcessor : ICommandProcessor<RegisterMemberCard>
    {
        private readonly IRepository<Member> _memberRepository;

        public RegisterMemberCardProcessor(IRepository<Member> memberRepository)
        {
            _memberRepository = memberRepository;
        }

        public dynamic Process(RegisterMemberCard command)
        {
            var member = _memberRepository.GetById(command.Id);

            member.TagId = command.TagId;

            _memberRepository.Update(member);

            return new MemberResponse
            {
                Id = member.Id,
                Code = member.Code,
                TagId = member.TagId,
                Address = member.Address,
                DateOfBirth = member.DateOfBirth,
                Email = member.Email,
                Mobile = member.Mobile,
                Name = member.Name,
                ScreenMessage = member.ScreenMessage,
                ValidFrom = member.ValidFrom,
                ValidTo = member.ValidTo                
            };
        }
    }
}